package com.geeksaga.dao.ibatis.oracle;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.geeksaga.common.util.DateConvertor;
import com.geeksaga.dao.BbsTypeDao;
import com.geeksaga.dao.ibatis.BaseIBatisDao;
import com.geeksaga.domain.BbsType;
import com.geeksaga.domain.TableRowCount;

/**
 * @author newbie, casper0402
 * @since 0.1
 */
@Repository
public class BbsTypeDaoImpl extends BaseIBatisDao implements BbsTypeDao {

    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsTypeDao#list()
     */
    @SuppressWarnings("unchecked")
	public List<BbsType> list() throws DataAccessException {
		return (List<BbsType>) getSqlMapClientTemplate().queryForList("BBS_TYPE.list");
	}

	/* (non-Javadoc)
	 * @see com.geeksaga.dao.BbsTypeDao#list(java.util.Map)
	 */
	@SuppressWarnings("unchecked")
    public List<BbsType> list(Map<String, Object> parameter) throws DataAccessException {
	    return (List<BbsType>) getSqlMapClientTemplate().queryForList("BBS_TYPE.listByParameter", parameter);
	}

	/* (non-Javadoc)
	 * @see com.geeksaga.dao.BbsTypeDao#count(java.util.Map)
	 */
	public TableRowCount count(Map<String, Object> parameter) throws DataAccessException {
		return (TableRowCount) getSqlMapClientTemplate().queryForObject("BBS_TYPE.count", parameter);
	}

	/* (non-Javadoc)
	 * @see com.geeksaga.dao.BbsTypeDao#add(com.geeksaga.domain.BbsType)
	 */
	public BbsType add(BbsType bbsType) throws DataAccessException {
        bbsType.setRegistTimestamp(DateConvertor.getDateTimeFormat());
        
        return (BbsType) getSqlMapClientTemplate().insert("BBS_TYPE.add", bbsType);
	}

    /* (non-Javadoc)
     * @see com.geeksaga.dao.BbsTypeDao#updateCnt(com.geeksaga.domain.BbsType, com.geeksaga.domain.BbsType.CNT_TYPE)
     */
    public int updateCnt(BbsType bbsType, BbsType.CNT_TYPE type) throws DataAccessException {
        Map<String, String> param = new HashMap<String, String>();
        param.put("bbsId", bbsType.getBbsId());
        param.put("todayDate", bbsType.getTodayDate());

        if (BbsType.CNT_TYPE.TODAY_PLUS_CNT == type) {
            param.put("todayPlusCnt", "0");
            param.put("totalPlusCnt", "0");
            param.put("recodePlusCnt", "0");
        } else if (BbsType.CNT_TYPE.TODAY_MINUS_CNT == type) {
            param.put("todayMinusCnt", "0");
            param.put("totalMinusCnt", "0");
            param.put("recodeMinusCnt", "0");
        }

        return getSqlMapClientTemplate().update("BBS_TYPE.updateCnt", param);
    }
    
	/* (non-Javadoc)
	 * @see com.geeksaga.dao.BbsTypeDao#bbsUseModify(com.geeksaga.domain.BbsType)
	 */
	public int bbsUseModify(BbsType bbsType) throws DataAccessException {
        bbsType.setModifyTimestamp(DateConvertor.getDateTimeFormat());
        
        return getSqlMapClientTemplate().update("BBS_TYPE.bbsUseModify", bbsType);
	}

	public BbsType bbsView(BbsType bbsType) throws DataAccessException {
		// TODO Auto-generated method stub
		return null;
	}

	public int bbsAuthorityModify(BbsType bbsType) throws DataAccessException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int bbsScreenSetUp(BbsType bbsType) throws DataAccessException {
		// TODO Auto-generated method stub
		return 0;
	}

	public int bbsSecuritySetUp(BbsType bbsType) throws DataAccessException {
		// TODO Auto-generated method stub
		return 0;
	}
}